package main

import (
	"crypto/sha512"
	"encoding/hex"
	"fmt"
	"io"
	"bufio"
	"os"
        "path/filepath"
)

type Key struct {
	Size int64
	Digest string
}

var dupTable map[Key] []string

func simpleWalk(path string, info os.FileInfo, err error) error {
	theFile, err := os.Open(path)
        defer theFile.Close()

	reader := bufio.NewReader(theFile)
	hasher := sha512.New()
	_, err = io.Copy(hasher, reader)
	k := new (Key)
	k.Size = info.Size()
	if info.IsDir() {
		k.Digest = path
	} else {
		k.Digest = hex.EncodeToString(hasher.Sum(nil))
	}
	dupTable[*k] = append(dupTable[*k], path)
	return nil
}

func main() {
	dupTable = make(map[Key][]string)
	filepath.Walk(".", simpleWalk)
	for entry := range dupTable {
		e := dupTable[entry]
		fmt.Println(e)
		if len(e) > 1 {
			fmt.Println("Dup just seen above!")
		}
	}
}
